package com.kexio.scheduler.config;

import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * 定时任务配置属性
 * 
 * @author Kexio Team
 * @since 1.0.0
 */
@ConfigurationProperties(prefix = "kexio.scheduler")
public class SchedulerProperties {
    
    /**
     * 是否启用定时任务模块
     */
    private boolean enabled = true;
    
    /**
     * 调度器实例名称
     */
    private String instanceName = "KexioScheduler";
    
    /**
     * 线程池配置
     */
    private ThreadPool threadPool = new ThreadPool();
    
    /**
     * 任务持久化配置
     */
    private Persistence persistence = new Persistence();
    
    /**
     * 监控配置
     */
    private Monitor monitor = new Monitor();
    
    /**
     * 集群配置
     */
    private Cluster cluster = new Cluster();
    
    /**
     * 失败重试配置
     */
    private Retry retry = new Retry();
    
    public boolean isEnabled() {
        return enabled;
    }
    
    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }
    
    public String getInstanceName() {
        return instanceName;
    }
    
    public void setInstanceName(String instanceName) {
        this.instanceName = instanceName;
    }
    
    public ThreadPool getThreadPool() {
        return threadPool;
    }
    
    public void setThreadPool(ThreadPool threadPool) {
        this.threadPool = threadPool;
    }
    
    public Persistence getPersistence() {
        return persistence;
    }
    
    public void setPersistence(Persistence persistence) {
        this.persistence = persistence;
    }
    
    public Monitor getMonitor() {
        return monitor;
    }
    
    public void setMonitor(Monitor monitor) {
        this.monitor = monitor;
    }
    
    public Cluster getCluster() {
        return cluster;
    }
    
    public void setCluster(Cluster cluster) {
        this.cluster = cluster;
    }
    
    public Retry getRetry() {
        return retry;
    }
    
    public void setRetry(Retry retry) {
        this.retry = retry;
    }
    
    /**
     * 线程池配置
     */
    public static class ThreadPool {
        
        /**
         * 核心线程数
         */
        private int corePoolSize = 5;
        
        /**
         * 最大线程数
         */
        private int maximumPoolSize = 20;
        
        /**
         * 线程存活时间(秒)
         */
        private long keepAliveTime = 60;
        
        /**
         * 队列容量
         */
        private int queueCapacity = 100;
        
        /**
         * 线程名称前缀
         */
        private String threadNamePrefix = "kexio-scheduler-";
        
        public int getCorePoolSize() {
            return corePoolSize;
        }
        
        public void setCorePoolSize(int corePoolSize) {
            this.corePoolSize = corePoolSize;
        }
        
        public int getMaximumPoolSize() {
            return maximumPoolSize;
        }
        
        public void setMaximumPoolSize(int maximumPoolSize) {
            this.maximumPoolSize = maximumPoolSize;
        }
        
        public long getKeepAliveTime() {
            return keepAliveTime;
        }
        
        public void setKeepAliveTime(long keepAliveTime) {
            this.keepAliveTime = keepAliveTime;
        }
        
        public int getQueueCapacity() {
            return queueCapacity;
        }
        
        public void setQueueCapacity(int queueCapacity) {
            this.queueCapacity = queueCapacity;
        }
        
        public String getThreadNamePrefix() {
            return threadNamePrefix;
        }
        
        public void setThreadNamePrefix(String threadNamePrefix) {
            this.threadNamePrefix = threadNamePrefix;
        }
    }
    
    /**
     * 持久化配置
     */
    public static class Persistence {
        
        /**
         * 是否启用持久化
         */
        private boolean enabled = true;
        
        /**
         * 数据源名称
         */
        private String dataSource = "master";
        
        /**
         * 表前缀
         */
        private String tablePrefix = "t_scheduler_";
        
        public boolean isEnabled() {
            return enabled;
        }
        
        public void setEnabled(boolean enabled) {
            this.enabled = enabled;
        }
        
        public String getDataSource() {
            return dataSource;
        }
        
        public void setDataSource(String dataSource) {
            this.dataSource = dataSource;
        }
        
        public String getTablePrefix() {
            return tablePrefix;
        }
        
        public void setTablePrefix(String tablePrefix) {
            this.tablePrefix = tablePrefix;
        }
    }
    
    /**
     * 监控配置
     */
    public static class Monitor {
        
        /**
         * 是否启用监控
         */
        private boolean enabled = true;
        
        /**
         * 执行历史保留天数
         */
        private int historyRetentionDays = 30;
        
        /**
         * 统计数据刷新间隔(秒)
         */
        private int statisticsRefreshInterval = 60;
        
        public boolean isEnabled() {
            return enabled;
        }
        
        public void setEnabled(boolean enabled) {
            this.enabled = enabled;
        }
        
        public int getHistoryRetentionDays() {
            return historyRetentionDays;
        }
        
        public void setHistoryRetentionDays(int historyRetentionDays) {
            this.historyRetentionDays = historyRetentionDays;
        }
        
        public int getStatisticsRefreshInterval() {
            return statisticsRefreshInterval;
        }
        
        public void setStatisticsRefreshInterval(int statisticsRefreshInterval) {
            this.statisticsRefreshInterval = statisticsRefreshInterval;
        }
    }
    
    /**
     * 集群配置
     */
    public static class Cluster {
        
        /**
         * 是否启用集群模式
         */
        private boolean enabled = false;
        
        /**
         * 节点ID
         */
        private String nodeId;
        
        /**
         * 心跳间隔(秒)
         */
        private int heartbeatInterval = 30;
        
        /**
         * 节点超时时间(秒)
         */
        private int nodeTimeout = 120;
        
        public boolean isEnabled() {
            return enabled;
        }
        
        public void setEnabled(boolean enabled) {
            this.enabled = enabled;
        }
        
        public String getNodeId() {
            return nodeId;
        }
        
        public void setNodeId(String nodeId) {
            this.nodeId = nodeId;
        }
        
        public int getHeartbeatInterval() {
            return heartbeatInterval;
        }
        
        public void setHeartbeatInterval(int heartbeatInterval) {
            this.heartbeatInterval = heartbeatInterval;
        }
        
        public int getNodeTimeout() {
            return nodeTimeout;
        }
        
        public void setNodeTimeout(int nodeTimeout) {
            this.nodeTimeout = nodeTimeout;
        }
    }
    
    /**
     * 重试配置
     */
    public static class Retry {
        
        /**
         * 默认重试次数
         */
        private int maxRetryCount = 3;
        
        /**
         * 重试间隔(秒)
         */
        private int retryInterval = 60;
        
        /**
         * 重试策略: FIXED(固定间隔), EXPONENTIAL(指数退避)
         */
        private String strategy = "FIXED";
        
        public int getMaxRetryCount() {
            return maxRetryCount;
        }
        
        public void setMaxRetryCount(int maxRetryCount) {
            this.maxRetryCount = maxRetryCount;
        }
        
        public int getRetryInterval() {
            return retryInterval;
        }
        
        public void setRetryInterval(int retryInterval) {
            this.retryInterval = retryInterval;
        }
        
        public String getStrategy() {
            return strategy;
        }
        
        public void setStrategy(String strategy) {
            this.strategy = strategy;
        }
    }
}
